<html>
<head><meta charset="utf-8"><title>Is there a symbol for the empty string? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html">Is there a symbol for the empty string?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="219928215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219928215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219928215">(Dec 15 2020 at 01:40)</a>:</h4>
<p>I see <code>kw::Invalid</code> but that seems like a hack ... is there a sanctioned way to do this?</p>



<a name="219928220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219928220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219928220">(Dec 15 2020 at 01:40)</a>:</h4>
<p>maybe <span class="user-mention" data-user-id="274471">@Arlie Davis</span> knows?</p>



<a name="219928225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219928225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219928225">(Dec 15 2020 at 01:41)</a>:</h4>
<p>I can always <code>Symbol::intern("")</code> but that seems a waste</p>



<a name="219928246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219928246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Arlie Davis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219928246">(Dec 15 2020 at 01:41)</a>:</h4>
<p>I think both are fine, but I'd prefer kw::Invalid.</p>



<a name="219928298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219928298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219928298">(Dec 15 2020 at 01:42)</a>:</h4>
<p>huh, looks like Attribute does that too: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_ast/attr/mod.rs.html#145-147">https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_ast/attr/mod.rs.html#145-147</a></p>



<a name="219928300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219928300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219928300">(Dec 15 2020 at 01:42)</a>:</h4>
<p>thanks!</p>



<a name="219928330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219928330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219928330">(Dec 15 2020 at 01:43)</a>:</h4>
<p>(for context, I'm switching <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/types/struct.Item.html#structfield.name"><code>Item::name</code></a> from String to Symbol)</p>



<a name="219928495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219928495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219928495">(Dec 15 2020 at 01:46)</a>:</h4>
<p>do you think you'd take a PR adding <code>Symbol::is_empty()</code>?</p>



<a name="219928706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219928706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219928706">(Dec 15 2020 at 01:50)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/219928330">said</a>:</p>
<blockquote>
<p>(for context, I'm switching <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/types/struct.Item.html#structfield.name"><code>Item::name</code></a> from String to Symbol)</p>
</blockquote>
<p>and then I see things like</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">compare_impl</span><span class="o">&lt;'</span><span class="na">a</span><span class="p">,</span><span class="w"> </span><span class="o">'</span><span class="na">b</span><span class="o">&gt;</span><span class="p">(</span><span class="n">lhs</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="na">a</span> <span class="kp">&amp;&amp;</span><span class="nc">Impl</span><span class="p">,</span><span class="w"> </span><span class="n">rhs</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="na">b</span> <span class="kp">&amp;&amp;</span><span class="nc">Impl</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Ordering</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">lhs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">format</span><span class="o">!</span><span class="p">(</span><span class="s">"{}"</span><span class="p">,</span><span class="w"> </span><span class="n">lhs</span><span class="p">.</span><span class="n">inner_impl</span><span class="p">().</span><span class="n">print</span><span class="p">());</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">rhs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">format</span><span class="o">!</span><span class="p">(</span><span class="s">"{}"</span><span class="p">,</span><span class="w"> </span><span class="n">rhs</span><span class="p">.</span><span class="n">inner_impl</span><span class="p">().</span><span class="n">print</span><span class="p">());</span><span class="w"></span>

<span class="w">    </span><span class="c1">// lhs and rhs are formatted as HTML, which may be unnecessary</span>
<span class="w">    </span><span class="n">compare_names</span><span class="p">(</span><span class="o">&amp;</span><span class="n">lhs</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">rhs</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>and I wonder why I bother <span aria-label="sob" class="emoji emoji-1f62d" role="img" title="sob">:sob:</span></p>



<a name="219932876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219932876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219932876">(Dec 15 2020 at 03:12)</a>:</h4>
<p>is_empty might already exist? I feel like I've seen that though maybe not on Symbol itself</p>



<a name="219932897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219932897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219932897">(Dec 15 2020 at 03:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/219932876">said</a>:</p>
<blockquote>
<p>is_empty might already exist? I feel like I've seen that though maybe not on Symbol itself</p>
</blockquote>
<p>not on symbol: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Symbol.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Symbol.html</a></p>



<a name="219932915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/219932915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#219932915">(Dec 15 2020 at 03:13)</a>:</h4>
<p>you can use <code>symbol.as_str() == ""</code> but that locks the interner</p>



<a name="220046990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/220046990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Arlie Davis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#220046990">(Dec 15 2020 at 21:44)</a>:</h4>
<p>I think <code>symbol == kw::Invalid</code> is a good short-term equivalent for <code>is_empty</code> (and it won't need to lock the thread-local <code>Interner</code>). Maybe we need an alias of <code>sym::empty_string</code> for <code>kw::Invalid</code>, so that it's clear which meaning we're using.</p>



<a name="220054471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/220054471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#220054471">(Dec 15 2020 at 22:48)</a>:</h4>
<p>FWIW, we could just rename <code>kw::Invalid</code> to <code>kw::Empty</code>.</p>



<a name="220054634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/220054634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#220054634">(Dec 15 2020 at 22:50)</a>:</h4>
<p>I've looked through the uses of <code>kw::Invalid</code> and many of them would be clearer as <code>kw::Empty</code>.</p>



<a name="221182272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/221182272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#221182272">(Dec 30 2020 at 01:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123856">Vadim Petrochenkov</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471">said</a>:</p>
<blockquote>
<p>FWIW, we could just rename <code>kw::Invalid</code> to <code>kw::Empty</code>.</p>
</blockquote>
<p>working on this now</p>



<a name="221182571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20symbol%20for%20the%20empty%20string%3F/near/221182571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F.html#221182571">(Dec 30 2020 at 01:29)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/80495">https://github.com/rust-lang/rust/pull/80495</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>